package com.niit.config;

import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author： 曾渝晋
 * @date: 2021/6/22 11:28 下午
 * @description:
 * @modified:
 * @Version: 1.0
 */
@Component
@Primary
public class SwaggerConfig implements SwaggerResourcesProvider {
    @Override
    public List<SwaggerResource> get() {

        List<SwaggerResource> resources = new ArrayList<>();
        /**
         * zuul 中 routes添加的映射路径
         * 配置2个属性
         * 1. 模块名字 ---> 例如admin模块等/ 这里先用默认的模块admin-provider
         *
         * 2. 映射的路由路径(/admin-provider/**) + /v2/api-docs(swagger固定路径)
         */
        resources.add(getSwaggerResource("admin-provider", "/admin-provider/v2/api-docs", "2.0"));
        resources.add(getSwaggerResource("student-provider", "/student-provider/v2/api-docs", "2.0"));
        resources.add(getSwaggerResource("teacher-provider", "/teacher-provider/v2/api-docs", "2.0"));



        return resources;
    }

    private SwaggerResource getSwaggerResource(String name, String location,String version) {
        SwaggerResource swaggerResource = new SwaggerResource();
        swaggerResource.setName(name);
        swaggerResource.setLocation(location);
        swaggerResource.setSwaggerVersion(version);
        return swaggerResource;
    }

}
